package com.goods.controller.busniess;

import com.github.pagehelper.PageInfo;
import com.goods.business.service.ConsumerService;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.ConsumerVO;
import com.goods.common.vo.business.ProductVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @description：
 * @version: 物资 去处
 * @author：ruixinag
 * @create：Created in 2021/11/9 16:05
 */
@Api(tags = "业务模块-物资去处相关")
@RestController
@RequestMapping("/business/consumer")
public class ConsumerController {
    @Autowired
    private ConsumerService consumerService;

    //findConsumerList
    //物资去处分页列表展示
    @ApiOperation("物资去处分页列表展示")
    @GetMapping("/findConsumerList")
    public ResponseBean findConsumerList(@RequestParam Map paramMap){
       //PageInfo<ConsumerVO> pageInfo= consumerService.findConsumerList(paramMap);
       // Map map=new HashMap();
       // map.put("rows",pageInfo!=null?pageInfo.getList():new ArrayList<ConsumerVO>());
       // map.put("total",pageInfo!=null?pageInfo.getTotal():null);


        Map map=consumerService.findConsumerList(paramMap);

        return ResponseBean.success(map);
    }


    //添加物资去处
    @ApiOperation("添加物资去处")
    @PostMapping("/add")
    public ResponseBean add(@RequestBody ConsumerVO consumerVO){
       consumerService.add(consumerVO);
        return ResponseBean.success();
    }

    //修改,数据回显
    @ApiOperation("数据回显")
    @GetMapping("/edit/{consumerId}")
    public ResponseBean<ConsumerVO> edit(@PathVariable Long consumerId){
        ConsumerVO consumerVO= consumerService.edit(consumerId);
        return ResponseBean.success(consumerVO);
    }

    //更新数据
    @ApiOperation("数据回显")
    @PutMapping("/update/{consumerId}")
    public ResponseBean update(@PathVariable Long consumerId,@RequestBody ConsumerVO consumerVO){
         consumerService.update(consumerVO);
        return ResponseBean.success();
    }

    //删除数据
    @ApiOperation("删除数据")
    @DeleteMapping("/delete/{consumerId}")
    public ResponseBean delete(@PathVariable Long consumerId){
        consumerService.delete(consumerId);
        return ResponseBean.success();
    }

    //获取全部去处,findAll
    @ApiOperation("获取全部去处")
    @GetMapping("/findAll")
    public ResponseBean<List<ConsumerVO>> findAll(){
       List<ConsumerVO> list= consumerService.findAll();
        return ResponseBean.success(list);
    }


}
